﻿using System;

using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Caching.Memory;

using Utils.Buffer;

namespace Microsoft.AspNetCore.Mvc
{
    public class AdminToken : AuthIdentity
    {


        public readonly IMemoryCache memoryCache;


        public int AdminId { get; set; }



        public override bool Deserialize(byte[] encrypt, HttpContext httpContext)
        {
            try
            {
                var descrypt = ByteReadBuffer.Wrap(encrypt);
                AdminId = descrypt.ReadInt();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }

        public override byte[] Serialize()
        {
            var write = ByteWriteBuffer.Alloc();
            write.Write(AdminId);
            return write.ToBytes();
        }


    }


}
